package com.lizhi.menu.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lizhi.menu.Dto.CollectDto;
import com.lizhi.menu.Dto.IdListDto;
import com.lizhi.menu.common.response.Result;
import com.lizhi.menu.domain.Collect;
import com.lizhi.menu.service.ICollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 菜谱收藏Controller
 *
 * @author lizhi
 * @date 2023-05-18
 */
@RestController
@RequestMapping("/system/collect")
@RequiredArgsConstructor
@Api(tags = "菜谱收藏管理")
public class CollectController {
    private final ICollectService collectService;

    /**
     * 查询菜谱收藏列表
     */
    @GetMapping("/list")
    @ApiOperation("查询菜谱收藏列表")
    public Result<Page<Collect>> list(CollectDto dto) {
        return Result.ok(collectService.list(dto));
    }

    /**
     * 查询菜谱收藏列表
     */
    @GetMapping("/my")
    @ApiOperation("查询我的菜谱收藏列表")
    public Result<Page<Collect>> my(CollectDto dto) {
        dto.setUserId(Long.parseLong(StpUtil.getLoginId().toString()));
        return Result.ok(collectService.list(dto));
    }

    /**
     * 获取菜谱收藏详细信息
     */
    @GetMapping(value = "/{menuId}")
    @ApiOperation("获取菜谱收藏详细信息")
    public Result<Collect> getInfo(@PathVariable("menuId") Long menuId) {
        return Result.ok(collectService.getInfo(menuId));
    }

    /**
     * 新增菜谱收藏
     */
    @PostMapping
    @ApiOperation("新增菜谱收藏")
    public Result<Void> add(@RequestBody Collect collect) {
        collect.setUserId(StpUtil.getLoginId().toString());
        collectService.add(collect);
        return Result.ok();
    }

    /**
     * 修改菜谱收藏
     */
    @PutMapping
    @ApiOperation("修改菜谱收藏")
    public Result<Void> edit(@RequestBody Collect collect) {
        collectService.edit(collect);
        return Result.ok();
    }

    /**
     * 删除菜谱收藏
     */
    @DeleteMapping("/remove")
    @ApiOperation("删除菜谱收藏")
    public Result<Void> remove(@RequestBody IdListDto dto) {
        collectService.remove(dto.getIdList());
        return Result.ok();
    }
}
